# FDMpkg.py 
from struct import *
class fdmhdr:
	def __init__(self,x0=0.0,nx=0.0,dx=0.0,y0=0.0,ny=0.0,dy=0.0,z0=0.0,\
	nz=0.0,dz=0.0,vmin=0.0,vmax=0.0,fxl=1,fsl=1,xlinc=1,slinc=1):
		self.headers=[float(e-e) for e in range(0,128)]
		self.headers[0]=x0
		self.headers[1]=nx
		self.headers[2]=dx
		self.headers[3]=y0
		self.headers[4]=ny
		self.headers[5]=dy
		self.headers[6]=z0
		self.headers[7]=nz
		self.headers[8]=dz
		self.headers[12]=vmin
		self.headers[13]=vmax
		self.headers[14]=fxl
		self.headers[15]=fsl
		self.headers[16]=xlinc
		self.headers[17]=slinc
	def x0(self,val=None):
		if val!=None:
			self.headers[0]=val
		return self.headers[0]
	def nx(self,val=None):
		if val!=None:
			self.headers[1]=val
		return self.headers[1]
	def dx(self,val=None):
		if val!=None:
			self.headers[2]=val
		return self.headers[2]
	def y0(self,val=None):
		if val!=None:
			self.headers[3]=val
		return self.headers[3]
	def ny(self,val=None):
		if val!=None:
			self.headers[4]=val
		return self.headers[4]
	def dy(self,val=None):
		if val!=None:
			self.headers[5]=val
		return self.headers[5]
	def z0(self,val=None):
		if val!=None:
			self.headers[6]=val
		return self.headers[6]
	def nz(self,val=None):
		if val!=None:
			self.headers[7]=val
		return self.headers[7]
	def dz(self,val=None):
		if val!=None:
			self.headers[8]=val
		return self.headers[8]
	def vmin(self,val=None):
		if val!=None:
			self.headers[12]=val
		return self.headers[12]
	def vmax(self,val=None):
		if val!=None:
			self.headers[13]=val
		return self.headers[13]
	def fxl(self,val=None):
		if val!=None:
			self.headers[14]=val
		return self.headers[14]
	def fsl(self,val=None):
		if val!=None:
			self.headers[15]=val
		return self.headers[15]
	def xlinc(self,val=None):
		if val!=None:
			self.headers[16]=val
		return self.headers[16]
	def slinc(self,val=None):
		if val!=None:
			self.headers[17]=val
		return self.headers[17]
	def __getitem__(self,index):
		return self.headers[index]
def savefdm(filename,x,hdrs):
	file=open(filename,'wb')
	for i in range(0,128):
		file.write(pack('>f',hdrs[i]))
	for i in range(0,hdrs.nx()):
		for j in range(0,hdrs.ny()):
			for k in range(0,hdrs.nz()):
				file.write(pack('>f',x[i,j,k]))
	file.close()
